﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Extensions.XDocumentExtension
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Xml.Linq;


namespace LayersParser.Extensions;

public static class XDocumentExtension
{
  public static XElement GoToRoboticParams(this XDocument xDocument)
  {
    return xDocument.Root.Element((XName) "RoboticParams");
  }

  public static XElement GoToControllerInstalledVersions(
    this XDocument xDocument,
    string controllername)
  {
    return ((XContainer) xDocument.Root.Element((XName) "ControllersData").CheckingAttributes(controllername)).Element((XName) "InstalledVersions");
  }

  public static XElement GoToRoboticParams(this XDocument xDocument, string name)
  {
    return (XElement) xDocument.GoToRoboticParams().CheckingAttributes(name);
  }

  public static XElement GoToOlpCommands(this XDocument xDocument)
  {
    return xDocument.Root.Element((XName) "OlpCommands");
  }

  public static XElement GoToRoboticParamRef(
    this XDocument xDocument,
    string name,
    string relatedcommand)
  {
    return xDocument.GoToRoboticParamRef(relatedcommand).CheckingValue(name, "Param");
  }

  public static XElement GoToRoboticParamRef(this XDocument xDocument, string relatedcommand)
  {
    return xDocument.GoToCommand(relatedcommand).Element((XName) "RoboticParamRef");
  }

  public static XElement GoToRoboticParamRefProc(
    this XDocument xDocument,
    string name,
    string relatedcommand,
    string location)
  {
    return xDocument.GoToProcess(relatedcommand, location).Element((XName) "Dialog").Element((XName) "RoboticParamRef").CheckingValue(name, "Param");
  }

  public static XElement GoToRoboticParamRefProc(
    this XDocument xDocument,
    string relatedcommand,
    string location)
  {
    return xDocument.GoToProcess(relatedcommand, location).Element((XName) "Dialog").Element((XName) "RoboticParamRef");
  }

  public static XElement GoToCommand(this XDocument xDocument, string name)
  {
    return (XElement) xDocument.GoToOlpCommands().CheckingAttributes(name);
  }

  public static XElement GoToProcess(this XDocument xDocument, string name, string location)
  {
    return (XElement) xDocument.GoToLocation(location).CheckingAttributes(name);
  }

  public static XElement GoToOlpDialogs(this XDocument xDocument)
  {
    return xDocument.Root.Element((XName) "OlpDialogs");
  }

  public static XElement GoToOlpDialogs(this XDocument xDocument, string command)
  {
    foreach (XElement element1 in xDocument.GoToOlpDialogs().Elements((XName) "Dialog"))
    {
      foreach (XElement element2 in element1.Element((XName) "OlpCommandRef").Elements((XName) "OlpCommand"))
      {
        if (element2.Value == command)
          return element1;
      }
    }
    return (XElement) null;
  }

  public static XElement GoToLocation(this XDocument xDocument, string location)
  {
    foreach (XElement element in xDocument.Root.Elements((XName) "Location"))
    {
      if (element.Attribute((XName) "Type").Value == location)
        return element;
    }
    XElement content = new XElement((XName) "Location", (object) new XAttribute((XName) "Type", (object) location));
    xDocument.Root.Add((object) content);
    return content;
  }
}
